﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using TierApplication;
using System.Data;
using DevExpress.Web.ASPxEditors;

public partial class System_admin_SysPara : System.Web.UI.Page
{
    #region private
    P_SYSPARA mSYSPARA = new P_SYSPARA();
    private const string inputQueryStringIDKey = "SysID";
    private const string inputQueryStringPageModeKey = "pagemode";
    private const string currentPageModeKey = "CurrentPageMode";
    private const string mDataModel = "mDataModel";

    public enum PageMode
    {
        add,
        update
    }
    private Nullable<PageMode> pm;
    #endregion



    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            pm = ViewState[currentPageModeKey] as Nullable<PageMode>;
        }
        else
        {
            LoadSysParaData("0");
        }

    }

    private void LoadSysParaData(String SysID)
    {
        mSYSPARA.GetModel(SysID);
        ViewState[mDataModel] = mSYSPARA;
        this.txtEMAIL_SENDOR.Text = mSYSPARA.EMAIL_SENDOR;
        this.txtEMAIL_SERVER.Text = mSYSPARA.EMAIL_SERVER;
        this.txtEMAIL_PORT.Text = mSYSPARA.EMAIL_PORT.ToString();
        this.txtEMAIL_USER.Text = mSYSPARA.EMAIL_USER;
        this.txtEMAIL_PWD.Text = mSYSPARA.EMAIL_PWD;
        if (mSYSPARA.EMAIL_NEED_SMPT.ToString() == "1")
        {
            this.txtEMAIL_NEED_SMPT.Checked = true;
        }
    }

    protected void btnSchoolSave_Click(object sender, EventArgs e)
    {
        mSYSPARA.SYSID = "0";
        mSYSPARA.EMAIL_SENDOR = txtEMAIL_SENDOR.Text;
        mSYSPARA.EMAIL_SERVER = txtEMAIL_SERVER.Text;
        mSYSPARA.EMAIL_PORT = int.Parse(txtEMAIL_PORT.Text);
        mSYSPARA.EMAIL_USER = txtEMAIL_USER.Text;
        if (txtEMAIL_NEED_SMPT.Checked)
        {
            mSYSPARA.EMAIL_NEED_SMPT = 1;
        }
        else
        {
            mSYSPARA.EMAIL_NEED_SMPT = 0;
        }
        mSYSPARA.EMAIL_PWD = txtEMAIL_PWD.Text;

        //if (String.IsNullOrEmpty(sSchoolID))
        //{
        //    mSYSPARA.SCHOOLID = TranUtils.GetSchoolID();
        //    txtSCHOOLID.Text = mSYSPARA.SCHOOLID;
        //    mSYSPARA.Add();
        //}
        //else
        //{
        //    mSYSPARA.SCHOOLID = this.txtSCHOOLID.Text;
        //    mSYSPARA.Update();
        //}
        mSYSPARA.Update();

        this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功');</script>");
    }
    protected void btnEmailSendTest_Click(object sender, EventArgs e)
    {
        int iResult =0;
        string cResult ="";
        string sMailResv = txtEMAIL_RESV.Text;
        TranUtils.SP_SEND_EMAIL_TEST(sMailResv, ref iResult, ref cResult);
        if (iResult == 0)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('邮件发送测试成功,请至测试邮箱查看');</script>");
        }
        else
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('邮件发送失败,错误原因为：" + cResult + "');</script>");
        }

    }
}